package com.youyiwen.Mapper;

import com.youyiwen.Bean.Question;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: zhaoyang
 * @Date: 2021/03/18
 */
@Mapper
public interface QuestionMapper {
    public void insertQuestion(Question question);
    @Select("select * from Question limit #{offSet},#{size}")
    public List<Question> selectQuestions(@Param(value = "offSet") Integer offSet,
                                          @Param(value = "size")Integer size);


    @Select("select count(1) from question")
    public Integer count();


    @Select("select * from Question where id = #{id}")
    public Question getById(@Param(value = "id") String id);

    @Update("update question set title = #{title},description = #{description} where id = #{id}")
    public void updateQuestion(@Param(value="title") String title,
                               @Param(value="description") String description,
                               @Param(value="id") String id);

    @Update("update question set viewCount = viewCount + 1 where id = #{id}")
    public void updateViewCount(@Param(value = "id") String id);

    @Update("update question set commentCount = commentCount + 1 where id = #{id}")
    public void updateCommentCount(@Param(value = "id") String id);

    @Select("select title from question where id = #{id}")
    public String selectTitleById(String id);

    @Select("select userName from question where id = #{id}")
    public String selectUserNameById(String id);

    @Select("select * from question where userName = #{userName}")
    public List<Question> selectQuestionsByUserName(String userName);
}
